import gen.YYParser;
import bison.LexToken;

#if cpp
import cpp.Lib;
import cpp.io.File;
import cpp.Sys;
#else
import neko.Lib;
import neko.io.File;
import neko.Sys;
#end

class Main
{


   public static function main()
   {
      var args = Sys.args();
      var filename = args[0];
    
      if (filename==null)
         throw "Usage : Main -|filename";
   
      var symbols = new Hash<Float>();
      symbols.set("PI",Math.PI);
      YYParser.errorVerbose = true;

      if ( filename!="-" ) // Pull mode ...
      {
         var lexer = new MyLexer( File.getContent(filename), filename );
         var parser = new YYParser(lexer,symbols);
         parser.output = Lib.println;
         parser.parse();
      }
      else
      {
         var input = File.stdin();
         var lexer = new MyLexer("","stdin");
         var parser = new YYParser(null,symbols);
         parser.output = Lib.println;
         parser.errorFunction = function(message:String,info:Dynamic)
         {
            trace(message + (info==null ? "" : info) );
            return YYParser.YYERROR;
         }

         try
         {
            while(true)
            {
               var line = input.readLine();
               if (line=="quit")
                  break;
               if (!lexer.parseInput(parser,line+"\n"))
                  break;
            }
         }
         catch(eof:Dynamic)
         {
            //trace(eof);
         }
      }
   }
}

